package golang

func main() {
	for i := 0; i < 5; i++ {
		defer func() {
			println(i)
		}()
	}
}

/**
解决办法
func main() {
    for i := 0; i < 5; i++ {
        i := i
        defer func() {
            println(i)
        }()
    }
}

或


func main() {
    for i := 0; i < 5; i++ {
        defer func(i int) {
            println(i)
        }(i)
    }
}
*/
